package com.zjt.pictureselector.model;

import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.NonNull;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2017</p>
 * <P>Company: </p>
 *
 * @author zhengjianting
 * @time 2017/11/9 0009 上午 10:15
 */

public class MediaBean implements Comparable<MediaBean>, Parcelable{

    private Type type;
    private String path;
    private long size;
    private String disPlayName;
    private String thumbPath;
    private int duration;
    private long addTime;
    private boolean isSelect;

    public MediaBean(Type type, String path, long size, String disPlayName, long addTime) {
        this.type = type;
        this.path = path;
        this.size = size;
        this.disPlayName = disPlayName;
        this.addTime = addTime;
    }

    public MediaBean(Type type, String path, String thumbPath, int duration, long size, String disPlayName, long addTime) {
        this.type = type;
        this.path = path;
        this.thumbPath = thumbPath;
        this.duration = duration;
        this.size = size;
        this.disPlayName = disPlayName;
        this.addTime = addTime;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public long getSize() {
        return size;
    }

    public void setSize(long size) {
        this.size = size;
    }

    public String getDisPlayName() {
        return disPlayName;
    }

    public void setDisPlayName(String disPlayName) {
        this.disPlayName = disPlayName;
    }

    public Type getType() {
        return type;
    }

    public void setType(Type type) {
        this.type = type;
    }

    public String getThumbPath() {
        return thumbPath;
    }

    public void setThumbPath(String thumbPath) {
        this.thumbPath = thumbPath;
    }

    public int getDuration() {
        return duration;
    }

    public void setDuration(int duration) {
        this.duration = duration;
    }

    public long getAddTime() {
        return addTime;
    }

    public void setAddTime(long addTime) {
        this.addTime = addTime;
    }

    public boolean isSelect() {
        return isSelect;
    }

    public void setSelect(boolean select) {
        isSelect = select;
    }

    @Override
    public int compareTo(@NonNull MediaBean mediaBean) {
        if (addTime < mediaBean.addTime) {
            return 1;
        } else if (addTime > mediaBean.addTime) {
            return -1;
        }
        return 0;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel out, int flags) {
        out.writeParcelable(type, flags);
        out.writeString(path);
        out.writeLong(size);
        out.writeString(disPlayName);
        out.writeString(thumbPath);
        out.writeInt(duration);
        out.writeLong(addTime);
        out.writeByte((byte)(isSelect?1:0));
    }

    public static final Parcelable.Creator<MediaBean> CREATOR = new Creator<MediaBean>() {
        @Override
        public MediaBean createFromParcel(Parcel source) {
            return new MediaBean(source);
        }

        @Override
        public MediaBean[] newArray(int size) {
            return new MediaBean[size];
        }
    };

    public MediaBean(Parcel in){
        type = in.readParcelable(Type.class.getClassLoader());
        path = in.readString();
        size = in.readLong();
        disPlayName = in.readString();
        thumbPath = in.readString();
        duration = in.readInt();
        addTime = in.readLong();
        isSelect = in.readByte()!= 0;
    }

    public enum Type implements Parcelable{
        Image, Video;

        @Override
        public void writeToParcel(Parcel dest, int flags) {
            dest.writeInt(ordinal());
        }

        @Override
        public int describeContents() {
            return 0;
        }

        public static final Creator<Type> CREATOR = new Creator<Type>() {
            @Override
            public Type createFromParcel(Parcel in) {
                return Type.values()[in.readInt()];
            }

            @Override
            public Type[] newArray(int size) {
                return new Type[size];
            }
        };
    }
}
